<template>
    <div id="parts" class="hospital">
        <el-button v-if="unitId != '0'" @click="insertList" class="slot-btn-top" type="primary" size="small">增加服务</el-button>
        <el-table :data="listdata.slice((currentPage-1)*pagesize,currentPage*pagesize)" stripe border :height="tableHeight" :header-cell-style="getRowClass">
            <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
            <el-table-column prop="hospitalName" label="服务需求客户" sortable min-width="280"></el-table-column>
            <el-table-column prop="serviceTypeName" label="服务类型" sortable min-width="140"></el-table-column>
            <el-table-column prop="applicantTime" label="申请时间" sortable min-width="170"></el-table-column>
            <el-table-column prop="serviceNeedTime" label="服务需求日期" sortable min-width="170"></el-table-column>
            <el-table-column prop="serviceStateName" label="申请状态" sortable min-width="120"></el-table-column>
            <el-table-column prop="sureServiceTime" label="确定服务处理日期" sortable min-width="170"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" min-width="80">
                <template slot-scope="scope">
                    <el-button v-if="unitId != '0'" @click="updateList(scope.row)" type="text" size="small"> {{ scope.row.serviceState =='0' ? '编辑' : (scope.row.serviceState =='1' ? '评价' : '详情')}}</el-button>
                    <el-button v-if="unitId == '0'" @click="updateList(scope.row)" type="text" size="small">{{ scope.row.serviceState =='0' ? '审核' : '详情' }}</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagesize" layout="total, sizes, prev, pager, next, jumper" :total="listdata.length"></el-pagination>

        <!--详情窗口-->
        <el-dialog  :title="dialogTitle" width="75%" top="50px" :visible.sync="isDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">

            <el-tabs v-model="activeName" @tab-click="handleClick" style="padding-bottom: 15px;">
                <el-tab-pane label="基本信息" name="1" :style="dialogHeight">
                    <h3 class="dialog-plate-title" style="margin-bottom: 20px"><span>基本信息</span></h3>
                    <el-form :inline="true" class="demo-form-inline" v-model="insertData" label-position="right" label-width="200px">
                        <el-form-item label="服务类型"><el-select v-model="insertData.serviceType" :disabled="!insertDataDisabled.serviceType" filterable allow-create default-first-option placeholder="请输入服务名称"><el-option v-for="item in ServerName" :key="item.id" :label="item.serviceName" :value="item.id"></el-option></el-select></el-form-item>
                        <el-form-item label="服务医院"><el-select v-model="insertData.hospital" :disabled="!insertDataDisabled.hospital" filterable allow-create default-first-option placeholder="请输入医院名称"><el-option v-for="item in hospitalName" :key="item.id" :label="item.hospitalName" :value="item.id"></el-option></el-select></el-form-item>
                        <el-form-item label="医院科室"><el-select v-model="insertData.department" :disabled="!insertDataDisabled.department" filterable allow-create default-first-option placeholder="请输入医院科室名称"><el-option v-for="item in applyOffice" :key="item.code" :label="item.name" :value="item.code"></el-option></el-select></el-form-item>
                        <el-form-item label="服务需求日期"><el-date-picker v-model="insertData.serviceNeedTime" :disabled="!insertDataDisabled.serviceNeedTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="是否接受其他经销商服务"><el-select v-model="insertData.isAcceptOthersService" :disabled="!insertDataDisabled.isAcceptOthersService" ><el-option value="0" label="接受"></el-option><el-option value="1" label="拒绝"></el-option></el-select></el-form-item>
                        <el-form-item label="申请人"><el-input v-model="insertData.applicantName" :disabled="!insertDataDisabled.applicantName"></el-input></el-form-item>
                        <el-form-item label="申请时间"><el-input v-model="insertData.applicantTime" :disabled="!insertDataDisabled.applicantTime"></el-input></el-form-item>
                    </el-form>
                    <el-form v-model="insertData" label-position="right" label-width="200px">
                        <el-form-item label="服务背景描述"><el-input v-model="insertData.needServiceDesc"  :disabled="!insertDataDisabled.needServiceDesc" type="textarea" :rows="3" style="width:97%"></el-input></el-form-item>
                    </el-form>

                    <h3 v-if="dialogTitle !== '服务申请'" class="dialog-plate-title" style="margin-bottom: 20px"><span>审核信息</span></h3>
                    <el-form v-if="dialogTitle !== '服务申请'" :inline="true" class="demo-form-inline" v-model="insertData" label-position="right" label-width="200px">
                        <el-form-item label="审核结果">
                            <el-select v-model="insertData.approveResult" :disabled="!insertDataDisabled.approveResult">
                                <el-option value="0" label="待审核"></el-option>
                                <el-option value="1" label="已审核"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="确定服务处理日期"><el-date-picker v-model="insertData.sureServiceTime" :disabled="!insertDataDisabled.sureServiceTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                        <el-form-item label="最终服务单位">

                            <el-input v-if="!insertDataDisabled.lastServiceDept" v-model="insertData.lastServiceDeptName" :disabled="!insertDataDisabled.lastServiceDeptName"></el-input>
                            <el-select v-else v-model="insertData.lastServiceDept" :disabled="!insertDataDisabled.lastServiceDept">
                                <el-option v-for="item in serviceDepts" :key="item.id" :value="item.id" :label="item.name"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item label="提供服务人员"><el-input v-model="insertData.servicer" :disabled="!insertDataDisabled.servicer"></el-input></el-form-item>
                        <el-form-item label="服务人员联系方式"><el-input v-model="insertData.servicerPhone" :disabled="!insertDataDisabled.servicerPhone"></el-input></el-form-item>
                        <el-form-item label="服务审核人"><el-input v-model="insertData.approverName" :disabled="!insertDataDisabled.approverName"  ></el-input></el-form-item>
                        <el-form-item label="服务审核日期"><el-date-picker v-model="insertData.approveTime" :disabled="!insertDataDisabled.approveTime"  format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                    </el-form>
                    <el-form v-if="dialogTitle !== '服务申请'" v-model="insertData" label-position="right" label-width="200px">
                        <el-form-item label="审核批注"><el-input v-model="insertData.approveRemark" :disabled="!insertDataDisabled.approveRemark" type="textarea" :rows="2"  style="width:98%" ></el-input></el-form-item>
                    </el-form>

                    <h3 v-if="dialogTitle !== '服务申请'" class="dialog-plate-title" style="margin-bottom: 20px"><span>服务评价</span></h3>
                    <el-form v-if="dialogTitle !== '服务申请'" v-model="insertData" label-position="right" label-width="200px">
                        <el-form-item label="服务评价"><el-input v-model="insertData.serviceEvaluation" :disabled="!insertDataDisabled.serviceEvaluation" type="textarea" :rows="2" style="width:98%" ></el-input></el-form-item>
                    </el-form>
                    <div class="dialog-footer" style="text-align: center;"><el-button @click="submitList" type="primary">确 定</el-button></div>
                </el-tab-pane>
                <el-tab-pane v-if="dialogTitle !== '服务申请'"  label="地图统计" name="2" :style="dialogHeight">
                    <el-form :inline="true" class="demo-form-inline" v-model="mapList" label-position="right" label-width="130px" >
                        <el-select v-model="mapList.type">
                            <el-option v-for="item in serviceTypes" :key="item.id" :value="item.id" :label="item.serviceName"></el-option>
                        </el-select>
                        <el-date-picker v-model="mapList.dateTime" type="datetimerange" :picker-options="pickerOptions2" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" align="right"></el-date-picker>
                        <el-button type="primary" @click="getMapCharts">查询</el-button>
                    </el-form>
                    <div style="margin-bottom: 10px;">
                        <span @click="toggleVisible('0')" style="height: 40px;margin-right: 20px;cursor:pointer;"><img ref="icon0" src="../../../../static/img/icon01.png" alt="" style="width: 30px;height: 20px;">需求客户【未审核】</span>
                        <span @click="toggleVisible('1')" style="height: 40px;margin-right: 20px;cursor:pointer;"><img ref="icon1" src="../../../../static/img/icon02.png" alt="" style="width: 30px;height: 20px;">需求客户【已审核】</span>
                        <span @click="toggleVisible('2')" style="height: 40px;margin-right: 20px;cursor:pointer;"><img ref="icon2" src="../../../../static/img/icon_wj02.png" alt="" style="width: 30px;height: 20px;">提供服务的经销商</span>
                        <span @click="toggleVisible('3')" style="height: 40px;margin-right: 20px;cursor:pointer;"><img ref="icon3" src="../../../../static/img/icon_wj04.png" alt="" style="width: 30px;height: 20px;">生产厂商</span>
                    </div>
                    <div class="amap-page-container" >
                        <el-amap vid="amapDemo" :plugin="plugin" :center="center" :zoom="zoom" class="amap-demo">
                            <el-amap-marker v-for="marker in markers" :key="markers.applyStatus" :position="marker.position" :icon="marker.icon" :animation="marker.animation" :visible="marker.visible" :events="marker.events"></el-amap-marker>
                            <el-amap-info-window v-if="false" :position="window.position" :visible="window.content" :template="window.content" ></el-amap-info-window>
                        </el-amap>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </el-dialog>


        <!-- 审核详细 -->
        <el-dialog  :title="dialogExamineTitle" width="75%" top="50px" :visible.sync="isExamineDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <div :style="dialogHeight">
                <h3 class="dialog-plate-title" style="margin-bottom: 20px"><span>基本信息</span></h3>
                <el-form :inline="true" class="demo-form-inline" v-model="insertExamineData" label-position="right" label-width="200px">
                    <el-form-item label="服务类型"><el-select v-model="insertExamineData.serviceType" :disabled="!insertExamineDataDisabled.serviceType" filterable allow-create default-first-option placeholder="请输入服务名称"><el-option v-for="item in ServerName" :key="item.id" :label="item.serviceName" :value="item.id"></el-option></el-select></el-form-item>
                    <el-form-item label="服务医院"><el-select v-model="insertExamineData.hospital" :disabled="!insertExamineDataDisabled.hospital" filterable allow-create default-first-option placeholder="请输入医院名称"><el-option v-for="item in hospitalName" :key="item.id" :label="item.hospitalName" :value="item.id"></el-option></el-select></el-form-item>
                    <el-form-item label="医院科室"><el-select v-model="insertExamineData.department" :disabled="!insertExamineDataDisabled.department" filterable allow-create default-first-option placeholder="请输入医院科室名称"><el-option v-for="item in applyOffice" :key="item.code" :label="item.name" :value="item.code"></el-option></el-select></el-form-item>
                    <el-form-item label="服务需求日期"><el-date-picker v-model="insertExamineData.serviceNeedTime" :disabled="!insertExamineDataDisabled.serviceNeedTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                    <el-form-item label="是否接受其他经销商服务"><el-select v-model="insertExamineData.isAcceptOthersService" :disabled="!insertExamineDataDisabled.isAcceptOthersService" ><el-option value="0" label="接受"></el-option><el-option value="1" label="拒绝"></el-option></el-select></el-form-item>
                    <el-form-item label="申请人"><el-input v-model="insertExamineData.applicantName" :disabled="!insertExamineDataDisabled.applicantName"></el-input></el-form-item>
                    <el-form-item label="申请时间"><el-input v-model="insertExamineData.applicantTime" :disabled="!insertExamineDataDisabled.applicantTime"></el-input></el-form-item>
                </el-form>
                <el-form v-model="insertExamineData" label-position="right" label-width="200px">
                    <el-form-item label="服务背景描述"><el-input v-model="insertExamineData.needServiceDesc"  :disabled="!insertExamineDataDisabled.needServiceDesc" type="textarea" :rows="3" style="width:97%"></el-input></el-form-item>
                </el-form>

                <h3 v-if="dialogTitle !== '服务申请'" class="dialog-plate-title" style="margin-bottom: 20px"><span>审核信息</span></h3>
                <el-form v-if="dialogTitle !== '服务申请'" :inline="true" class="demo-form-inline" v-model="insertExamineData" label-position="right" label-width="200px">
                    <el-form-item label="审核结果">
                        <el-select v-model="insertExamineData.approveResult" :disabled="!insertExamineDataDisabled.approveResult">
                            <el-option value="0" label="待审核"></el-option>
                            <el-option value="1" label="已审核"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="确定服务处理日期"><el-date-picker v-model="insertExamineData.sureServiceTime" :disabled="!insertExamineDataDisabled.sureServiceTime" format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                    <el-form-item label="最终服务单位">
                        <el-select v-model="insertExamineData.lastServiceDept" :disabled="!insertExamineDataDisabled.lastServiceDept">
                            <el-option v-for="item in serviceDepts" :key="item.id" :value="item.id" :label="item.name"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="提供服务人员"><el-input v-model="insertExamineData.servicer" :disabled="!insertExamineDataDisabled.servicer"></el-input></el-form-item>
                    <el-form-item label="服务人员联系方式"><el-input v-model="insertExamineData.servicerPhone" :disabled="!insertExamineDataDisabled.servicerPhone"></el-input></el-form-item>
                    <el-form-item label="服务审核人"><el-input v-model="insertExamineData.approverName" :disabled="!insertExamineDataDisabled.approverName"  ></el-input></el-form-item>
                    <el-form-item label="服务审核日期"><el-date-picker v-model="insertExamineData.approveTime" :disabled="!insertExamineDataDisabled.approveTime"  format="yyyy-MM-dd" type="date" placeholder="选择日期时间" style="width: 200px;"></el-date-picker></el-form-item>
                </el-form>
                <el-form v-if="dialogTitle !== '服务申请'" v-model="insertExamineData" label-position="right" label-width="200px">
                    <el-form-item label="审核批注"><el-input v-model="insertExamineData.approveRemark" :disabled="!insertExamineDataDisabled.approveRemark" type="textarea" :rows="2"  style="width:98%" ></el-input></el-form-item>
                </el-form>

                <h3 v-if="dialogTitle !== '服务申请'" class="dialog-plate-title" style="margin-bottom: 20px"><span>服务评价</span></h3>
                <el-form v-if="dialogTitle !== '服务申请'" v-model="insertExamineData" label-position="right" label-width="200px">
                    <el-form-item label="服务评价"><el-input v-model="insertExamineData.serviceEvaluation" :disabled="!insertExamineDataDisabled.serviceEvaluation" type="textarea" :rows="2" style="width:98%" ></el-input></el-form-item>
                </el-form>
            </div>
            <div slot="footer" class="dialog-footer" style="text-align: center;"><el-button @click="submitExamineList" type="primary">确 定</el-button></div>
        </el-dialog>

        <!-- 经销商详细 -->
        <el-dialog  title="详细" width="75%" top="80px" :visible.sync="isDistributorDialog" :close-on-click-modal="false" style="padding-bottom: 15px;">
            <div :style="dialogHeight">
                <h3 class="dialog-plate-title"><span>基本信息</span></h3>
                <el-form :inline="true" class="demo-form-inline" label-position="right" label-width="150px" :model="dialogDistributorList">
                    <el-form-item label="企业名称"><el-input v-model="dialogDistributorList.name" disabled></el-input></el-form-item>
                    <el-form-item label="企业电话"><el-input v-model="dialogDistributorList.phone" disabled></el-input></el-form-item>
                    <el-form-item label="企业邮箱"><el-input v-model="dialogDistributorList.email" disabled></el-input></el-form-item>
                    <el-form-item label="企业网站"><el-input v-model="dialogDistributorList.web" disabled></el-input></el-form-item>
                    <el-form-item label="经销商管理人员"><el-input v-model="dialogDistributorList.jyManagerName" disabled></el-input></el-form-item>
                </el-form>
                <el-form :inline="true" class="demo-form-inline" label-position="right" label-width="150px" :model="dialogDistributorList">
                    <el-form-item label="现企业经营地址">
                        <div style="width: 610px;">
                            <el-input v-model="dialogDistributorList.province" style="width: 200px;" disabled ></el-input>
                            <el-input v-model="dialogDistributorList.city" style="width: 200px;" disabled ></el-input>
                            <el-input v-model="dialogDistributorList.zone" style="width: 200px;" disabled ></el-input>
                           <el-input v-model="dialogDistributorList.address" style="margin-top: 5px;" disabled type="textarea" :rows="2" ></el-input>
                        </div>
                    </el-form-item>
                </el-form>
                <el-form label-position="right" label-width="150px" :model="dialogDistributorList">
                    <el-form-item label="经营范围"><el-input v-model="dialogDistributorList.businessScope" disabled type="textarea" :row="3" style="width: 97%;"></el-input></el-form-item>
                    <el-form-item label="企业简介"><el-input v-model="dialogDistributorList.introduction" disabled type="textarea" :row="8" style="width: 97%;"></el-input></el-form-item>
                    <el-form-item label="备注说明"><el-input v-model="dialogDistributorList.remark" disabled type="textarea" :row="8" style="width: 97%;"></el-input></el-form-item>
                </el-form>

                <h3 class="dialog-plate-title"><span>工商信息</span></h3>
                <el-form :inline="true" class="demo-form-inline" label-position="right" label-width="150px" :model="dialogDistributorList">
                    <el-form-item label="法人代表"><el-input v-model="dialogDistributorList.legalPerson" disabled></el-input></el-form-item>
                    <el-form-item label="注册资本（万元）"><el-input v-model="dialogDistributorList.registerCapital" disabled></el-input></el-form-item>
                    <el-form-item label="注册日期"><el-date-picker v-model="dialogDistributorList.registerDate" disabled type="date" placeholder="选择日期" style="width: 200px;"></el-date-picker></el-form-item>
                    <el-form-item label="统一社会信用代码"><el-input v-model="dialogDistributorList.creditCode" disabled></el-input></el-form-item>
                    <el-form-item label="登记机关"><el-input v-model="dialogDistributorList.registerOrgan" disabled></el-input></el-form-item>
                </el-form>
                <el-form :inline="true" class="demo-form-inline" label-position="right" label-width="150px" :model="dialogDistributorList">
                    <el-form-item label="工商注册地址">
                        <div style="width: 610px;">
                            <el-input v-model="dialogDistributorList.registerProvince" style="width: 200px;" disabled ></el-input>
                            <el-input v-model="dialogDistributorList.registerCity" style="width: 200px;" disabled ></el-input>
                            <el-input v-model="dialogDistributorList.registerZone" style="width: 200px;" disabled ></el-input>
                            <el-input v-model="dialogDistributorList.registerAddress" style="margin-top: 5px;"  disabled type="textarea" :rows="2" ></el-input>
                        </div>
                    </el-form-item>
                </el-form>
            </div>
        </el-dialog>


    </div>
</template>

<script>
    export default {
        data() {
            let date = new Date();
            let end = date.setDate(new Date(date.setHours(0, 0, 0, 0)).getDate() + 14);
            return {
                pickerOptions2: {
                    shortcuts: [
                        {
                            text: '最近一周',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                                picker.$emit('pick', [start, end]);
                            }
                        },
                        {
                            text: '最近一个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                                picker.$emit('pick', [start, end]);
                            }
                        },
                        {
                            text: '最近三个月',
                            onClick(picker) {
                                const end = new Date();
                                const start = new Date();
                                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                                picker.$emit('pick', [start, end]);
                            }
                        }
                    ]
                },
                tokenId: sessionStorage.getItem("tokenId"),
                unitId: sessionStorage.getItem("unitId"),
                currentPage: 1,
                pagesize: 10,
                activeName: '1',
                tableHeight: document.documentElement.clientHeight - (sessionStorage.getItem("unitId") == 0 ? 130 : 160 ),
                dialogHeight: {
                    height: document.documentElement.clientHeight - 220 + 'px',
                    minHeight: document.documentElement.clientHeight - 220 + 'px',
                    overflowY: 'auto',
                },
                listdata:[],
                ServerName:[],
                hospitalName:[],
                applyOffice:[],
                product:[],
                serviceDepts:[],

                //基本信息
                isDialog:false,
                dialogTitle:"",
                insertData:{
                    applicant: '',
                    applicantName: '',
                    applicantTime: '',
                    approveRemark: '',
                    approveResult: '',
                    approveTime: '',
                    approver: '',
                    approverName: '',
                    dealer: '',
                    dealerName: '',
                    department: '',
                    departmentName: '',
                    hospital: '',
                    hospitalName: '',
                    id: '',
                    isAcceptOthersService: '',
                    lastServiceDept: '',
                    lastServiceDeptName: '',
                    needServiceDesc: '',
                    serviceEvaluation: '',
                    serviceNeedTime: '',
                    serviceState: '',
                    serviceStateName: '',
                    serviceType: '',
                    serviceTypeName: '',
                    servicer: '',
                    servicerPhone: '',
                    sureServiceTime: '',
                },
                insertDataDisabled:{
                    applicant: false,
                    applicantName: false,
                    applicantTime: false,
                    approveRemark: false,
                    approveResult: false,
                    approveTime: false,
                    approver: false,
                    approverName: false,
                    dealer: false,
                    dealerName: false,
                    department: false,
                    departmentName: false,
                    hospital: false,
                    hospitalName: false,
                    id: false,
                    isAcceptOthersService: false,
                    lastServiceDept: false,
                    lastServiceDeptName: false,
                    needServiceDesc: false,
                    serviceEvaluation: false,
                    serviceNeedTime: false,
                    serviceState: false,
                    serviceStateName: false,
                    serviceType: false,
                    serviceTypeName: false,
                    servicer: false,
                    servicerPhone: false,
                    sureServiceTime: false,
                },

                //地图
                serviceTypes:[],
                mapList:{
                    type:1,
                    dateTime: [new Date(), end],
                },
                zoom: 5,
                center: [104.19025, 30.58958],
                markers: [],
                windows: [],
                groundimages: [],
                window: '',
                mapData: [],
                plugin: [{
                    pName: 'MapType',
                    defaultType: 0,
                    events: {
                        init(instance) {
                            console.log(instance);
                        }
                    }
                }],

                //审核详细信息
                isExamineDialog:false,
                dialogExamineTitle:"",
                insertExamineData:{
                    applicant: '',
                    applicantName: '',
                    applicantTime: '',
                    approveRemark: '',
                    approveResult: '',
                    approveTime: '',
                    approver: '',
                    approverName: '',
                    dealer: '',
                    dealerName: '',
                    department: '',
                    departmentName: '',
                    hospital: '',
                    hospitalName: '',
                    id: '',
                    isAcceptOthersService: '',
                    lastServiceDept: '',
                    lastServiceDeptName: '',
                    needServiceDesc: '',
                    serviceEvaluation: '',
                    serviceNeedTime: '',
                    serviceState: '',
                    serviceStateName: '',
                    serviceType: '',
                    serviceTypeName: '',
                    servicer: '',
                    servicerPhone: '',
                    sureServiceTime: '',
                },
                insertExamineDataDisabled:{
                    applicant: false,
                    applicantName: false,
                    applicantTime: false,
                    approveRemark: false,
                    approveResult: false,
                    approveTime: false,
                    approver: false,
                    approverName: false,
                    dealer: false,
                    dealerName: false,
                    department: false,
                    departmentName: false,
                    hospital: false,
                    hospitalName: false,
                    id: false,
                    isAcceptOthersService: false,
                    lastServiceDept: false,
                    lastServiceDeptName: false,
                    needServiceDesc: false,
                    serviceEvaluation: false,
                    serviceNeedTime: false,
                    serviceState: false,
                    serviceStateName: false,
                    serviceType: false,
                    serviceTypeName: false,
                    servicer: false,
                    servicerPhone: false,
                    sureServiceTime: false,
                },

                //经销商详细信息
                isDistributorDialog: false,
                dialogDistributorList: {
                    id:'',
                    name:'',
                    phone:'',
                    email:'',
                    province:'',
                    city:'',
                    zone:'',
                    address:'',
                    web:'',
                    jyManager:'',
                    jyManagerName:'',
                    introduction:'',
                    remark:'',
                    businessScope:'',
                    legalPerson:'',
                    registerCapital:'',
                    registerDate:'',
                    creditCode:'',
                    registerOrgan:'',
                    registerProvince:'',
                    registerCity:'',
                    registerZone:'',
                    registerAddress:'',
                    longitude:'',
                    latitude:'',
                },

            };
        },
        created() {
            this.selectAll();
            this.queryAllHospitalBaseList();
            this.hospital_office();
            this.selectServerName();
            this.getServiceType();
        },
        methods: {
            //查询服务名称
            selectServerName() {
                let _this = this;
                this.$http({
                    url: "/api/adscm/serviceProvider/jyServiceType/selectAll?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {
                    if (res.data.statusCode == 200) {
                        _this.ServerName = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                        _this.$message.error("加载失败！请重新加载...");
                    });
            },
            //查询服务类型列表
            selectAll() {
                let _this = this;
                this.$http({
                    url: "/api/adscm/serviceProvider/jyService/selectAll?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {
                    console.log(res.data);
                    if (res.data.statusCode == 200) {
                        _this.listdata = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                        _this.$message.error("加载失败！请重新加载...");
                });
            },
            queryAllHospitalBaseList() {
                let _this = this;
                this.$http({
                    url: "/api/adscm/dealer/jyHospitalBase/queryAllHospitalList?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {
                    if (res.data.statusCode == 200) {
                        _this.hospitalName = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                        _this.$message.error("加载失败！请重新加载...");
                    });
            },
            hospital_office() {
                let _this = this;
                this.$http({
                    url: "/api/adscm/system/code/queryCoedByType/hospital_office?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {
                    if (res.data.statusCode == 200) {
                        _this.applyOffice = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                        _this.$message.error("加载失败！请重新加载...");
                    });
            },
            getServiceDept(id){
                console.log( id )
                let _this = this;
                this.$http({
                    url: "/api/adscm/serviceProvider/jyService/queryLastServiceDept/"+id+"?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {

                    console.log(res.data )

                    if (res.data.statusCode == 200) {
                        _this.serviceDepts = res.data.content;

                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },

            // 基本信息
            insertList() {
                this.isDialog = true;
                this.dialogTitle = "服务申请";
                this.insertData = {
                    applicant: '',
                    applicantName: '',
                    applicantTime: '',
                    approveRemark: '',
                    approveResult: '',
                    approveTime: '',
                    approver: '',
                    approverName: '',
                    dealer: '',
                    dealerName: '',
                    department: '',
                    departmentName: '',
                    hospital: '',
                    hospitalName: '',
                    id: '',
                    isAcceptOthersService: '',
                    lastServiceDept: '',
                    lastServiceDeptName: '',
                    needServiceDesc: '',
                    serviceEvaluation: '',
                    serviceNeedTime: '',
                    serviceState: '',
                    serviceStateName: '',
                    serviceType: '',
                    serviceTypeName: '',
                    servicer: '',
                    servicerPhone: '',
                    sureServiceTime: '',
                };
                this.insertDataDisabled={
                    applicant: false,
                    applicantName: false,
                    applicantTime: false,
                    approveRemark: false,
                    approveResult: false,
                    approveTime: false,
                    approver: false,
                    approverName: false,
                    dealer: false,
                    dealerName: false,
                    department: true,
                    departmentName: true,
                    hospital: true,
                    hospitalName: true,
                    id: false,
                    isAcceptOthersService: true,
                    lastServiceDept: false,
                    lastServiceDeptName: false,
                    needServiceDesc: true,
                    serviceEvaluation: false,
                    serviceNeedTime: true,
                    serviceState: false,
                    serviceStateName: false,
                    serviceType: true,
                    serviceTypeName: true,
                    servicer: false,
                    servicerPhone: false,
                    sureServiceTime: false,
                };
            },
            updateList(row){
                this.getServiceDept(row.serviceType);
                this.isDialog = true;
                this.activeName = '1';
                this.insertData =row;
                this.insertData.serviceType =parseInt(row.serviceType);
                this.insertData.hospital =parseInt(row.hospital);
                if(row.serviceState == '0') {
                    if ( this.unitId != '0' ) {
                        this.dialogTitle = "编辑";
                        this.insertDataDisabled={
                            applicant: false,
                            applicantName: false,
                            applicantTime: false,
                            approveRemark: false,
                            approveResult: false,
                            approveTime: false,
                            approver: false,
                            approverName: false,
                            dealer: false,
                            dealerName: false,
                            department: true,
                            departmentName: true,
                            hospital: true,
                            hospitalName: true,
                            id: false,
                            isAcceptOthersService: true,
                            lastServiceDept: false,
                            lastServiceDeptName: false,
                            needServiceDesc: true,
                            serviceEvaluation: false,
                            serviceNeedTime: true,
                            serviceState: false,
                            serviceStateName: false,
                            serviceType: true,
                            serviceTypeName: true,
                            servicer: false,
                            servicerPhone: false,
                            sureServiceTime: false,
                        };
                    } else {
                        this.dialogTitle = "审核";
                        this.insertDataDisabled={
                            applicant: false,
                            applicantName: false,
                            applicantTime: false,
                            approveRemark: true,
                            approveResult: true,
                            approveTime: false,
                            approver: false,
                            approverName: false,
                            dealer: false,
                            dealerName: false,
                            department: false,
                            departmentName: false,
                            hospital: false,
                            hospitalName: false,
                            id: false,
                            isAcceptOthersService: false,
                            lastServiceDept: true,
                            lastServiceDeptName: true,
                            needServiceDesc: false,
                            serviceEvaluation: false,
                            serviceNeedTime: false,
                            serviceState: false,
                            serviceStateName: false,
                            serviceType: false,
                            serviceTypeName: false,
                            servicer: true,
                            servicerPhone: true,
                            sureServiceTime: true,
                        };
                    }
                } else if(row.serviceState == '1') {
                    this.dialogTitle = "评价";
                    this.insertDataDisabled={
                        applicant: false,
                        applicantName: false,
                        applicantTime: false,
                        approveRemark: false,
                        approveResult: false,
                        approveTime: false,
                        approver: false,
                        approverName: false,
                        dealer: false,
                        dealerName: false,
                        department: false,
                        departmentName: false,
                        hospital: false,
                        hospitalName: false,
                        id: false,
                        isAcceptOthersService: false,
                        lastServiceDept: false,
                        lastServiceDeptName: false,
                        needServiceDesc: false,
                        serviceEvaluation: true,
                        serviceNeedTime: false,
                        serviceState: false,
                        serviceStateName: false,
                        serviceType: false,
                        serviceTypeName: false,
                        servicer: false,
                        servicerPhone: false,
                        sureServiceTime: false,
                    };
                }else if(row.serviceState == '2') {
                    this.dialogTitle = "详情";
                    this.insertDataDisabled={
                        applicant: false,
                        applicantName: false,
                        applicantTime: false,
                        approveRemark: false,
                        approveResult: false,
                        approveTime: false,
                        approver: false,
                        approverName: false,
                        dealer: false,
                        dealerName: false,
                        department: false,
                        departmentName: false,
                        hospital: false,
                        hospitalName: false,
                        id: false,
                        isAcceptOthersService: false,
                        lastServiceDept: false,
                        lastServiceDeptName: false,
                        needServiceDesc: false,
                        serviceEvaluation: false,
                        serviceNeedTime: false,
                        serviceState: false,
                        serviceStateName: false,
                        serviceType: false,
                        serviceTypeName: false,
                        servicer: false,
                        servicerPhone: false,
                        sureServiceTime: false,
                    };
                }

                console.log( row )

            },
            submitList() {
                let _this = this;
                let url;
                if (this.dialogTitle === "服务申请") {
                    url = "/api/adscm/serviceProvider/jyService/insert?tokenId=" + _this.tokenId;
                } else {
                    url = "/api/adscm/serviceProvider/jyService/update?tokenId=" + _this.tokenId;
                }
                _this.insertData.serviceNeedTime=_this.timestampToTime(_this.insertData.serviceNeedTime);
                _this.insertData.sureServiceTime=_this.timestampToTime(_this.insertData.sureServiceTime);

                console.log( _this.insertData )

                this.$http({
                    url: url,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" },
                    data: _this.insertData
                }).then(function(res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.isDialog = false;
                        _this.selectAll();
                    }
                }).catch(function(catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },

            //地图
            getServiceType(){
                let _this = this;
                this.$http({
                    url: "/api/adscm/serviceProvider/jyServiceType/selectAll?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {
                    console.log( res.data )

                    if (res.data.statusCode == 200) {
                        _this.serviceTypes = res.data.content;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },
            getMapCharts(){
                let _this = this;
                let start = _this.timestampToTime(_this.mapList.dateTime[0]);
                let end = _this.timestampToTime(_this.mapList.dateTime[1]);
                this.$http({
                    url: '/api/adscm/serviceProvider/JyServiceChart/selectServiceChart/'+_this.mapList.type+'/'+start+'/'+end+'?tokenId=' + _this.tokenId,
                    method: 'post',
                    headers: {'X-Requested-With': 'XMLHttpRequest'},
                }).then(function (res) {
                    console.log(res.data)
                    if (res.data.statusCode == 200) {
                        _this.mapData = res.data.content;
                        _this.drawMapChart();
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function (catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                })
            },
            drawMapChart() {
                let self = this;
                let markers = [], windows = [];
                for (let j = 0; j < this.mapData.length; j++) {
                    let item = this.mapData[j];
                    if ( item.latitude && item.longitude ) {
                        markers.push({
                            position: [item.longitude, item.latitude],
                            applyStatus: item.state,
                            visible:true,
                            icon: (item.state == 0 ? '../../../../static/img/icon01.png' : (item.state == 1 ? '../../../../static/img/icon02.png' : (item.state == 2 ? '../../../../static/img/icon_wj02.png' : (item.state == 3 ? '../../../../static/img/icon_wj04.png' : "")))),
                            events: {
                                click() {
                                    self.windows.forEach(window => {window.visible = false;});
                                    self.window = self.windows[j];
                                    self.$nextTick(() => {
                                        //点击事件
                                        self.window.visible = false;
                                        if(item.state==0 || item.state==1){
                                            self.getExamineData(item.id);
                                        } else if(item.state==2){
                                            self.getDistributorData(item.id);
                                        }
                                    });
                                }
                            }
                        });
                        windows.push({
                            position: [item.longitude, item.latitude],
                            content: `<div class="prompt"><p>经销商名称：${item.dealer}</p></div>`,
                            visible: false,
                        });

                    }
                }
                this.markers = markers;
                this.windows = windows;
            },
            toggleVisible(idx) {
                let icon0 = '';
                let icon1 = '';
                let icon2 = '';
                let icon3 = '';
                let icon = '';
                let icon_wj = '';
                let icons = [icon0,icon1,icon2,icon3];
                for (let i = 0; i < this.markers.length; i++) {
                    let item = this.markers[i];
                    if (item.applyStatus == idx) {
                        let visableVar = this.markers[i].visible;
                        this.markers[i].visible = !visableVar;
                        if ( idx  == 2 || idx  == 3 ) {
                            this.$refs['icon'+idx].src = visableVar ? icon_wj : icons[idx];
                        } else {
                            this.$refs['icon'+idx].src = visableVar ? icon : icons[idx];
                        }
                    } else{
                        this.$refs['icon'+idx].src = ( idx  == 2 || idx  == 3 ) ? icon_wj : icon;
                    }
                }
            },


            // 获取审核详细数据
            getExamineData(id){
                let _this = this;
                this.$http({
                    url: "/api/adscm/serviceProvider/jyService/selectById/"+id+"?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.insertExamineData = res.data.content;
                        _this.getServiceDept(_this.insertExamineData.serviceType);
                        _this.isExamineDialog = true;
                        _this.insertExamineData.serviceType =parseInt(_this.insertExamineData.serviceType);
                        _this.insertExamineData.hospital =parseInt(_this.insertExamineData.hospital);


                       console.log(_this.unitId , _this.insertExamineData.serviceState )



                        if(_this.insertExamineData.serviceState == '0') {
                            if ( _this.unitId != '0' ) {
                                _this.dialogExamineTitle = "编辑";
                                _this.insertExamineDataDisabled={
                                    applicant: false,
                                    applicantName: false,
                                    applicantTime: false,
                                    approveRemark: false,
                                    approveResult: false,
                                    approveTime: false,
                                    approver: false,
                                    approverName: false,
                                    dealer: false,
                                    dealerName: false,
                                    department: true,
                                    departmentName: true,
                                    hospital: true,
                                    hospitalName: true,
                                    id: false,
                                    isAcceptOthersService: true,
                                    lastServiceDept: false,
                                    lastServiceDeptName: false,
                                    needServiceDesc: true,
                                    serviceEvaluation: false,
                                    serviceNeedTime: true,
                                    serviceState: false,
                                    serviceStateName: false,
                                    serviceType: true,
                                    serviceTypeName: true,
                                    servicer: false,
                                    servicerPhone: false,
                                    sureServiceTime: false,
                                };
                            } else {
                                _this.dialogExamineTitle = "审核";
                                _this.insertExamineDataDisabled={
                                    applicant: false,
                                    applicantName: false,
                                    applicantTime: false,
                                    approveRemark: true,
                                    approveResult: true,
                                    approveTime: false,
                                    approver: false,
                                    approverName: false,
                                    dealer: false,
                                    dealerName: false,
                                    department: false,
                                    departmentName: false,
                                    hospital: false,
                                    hospitalName: false,
                                    id: false,
                                    isAcceptOthersService: false,
                                    lastServiceDept: true,
                                    lastServiceDeptName: true,
                                    needServiceDesc: false,
                                    serviceEvaluation: false,
                                    serviceNeedTime: false,
                                    serviceState: false,
                                    serviceStateName: false,
                                    serviceType: false,
                                    serviceTypeName: false,
                                    servicer: true,
                                    servicerPhone: true,
                                    sureServiceTime: true,
                                };
                            }
                        } else if(_this.insertExamineData.serviceState == '1') {
                            _this.dialogExamineTitle = "评价";
                            _this.insertExamineData.lastServiceDept = _this.insertExamineData.lastServiceDeptName;
                            _this.insertExamineDataDisabled={
                                applicant: false,
                                applicantName: false,
                                applicantTime: false,
                                approveRemark: false,
                                approveResult: false,
                                approveTime: false,
                                approver: false,
                                approverName: false,
                                dealer: false,
                                dealerName: false,
                                department: false,
                                departmentName: false,
                                hospital: false,
                                hospitalName: false,
                                id: false,
                                isAcceptOthersService: false,
                                lastServiceDept: false,
                                lastServiceDeptName: false,
                                needServiceDesc: false,
                                serviceEvaluation: _this.unitId != '0' ? true :false,
                                serviceNeedTime: false,
                                serviceState: false,
                                serviceStateName: false,
                                serviceType: false,
                                serviceTypeName: false,
                                servicer: false,
                                servicerPhone: false,
                                sureServiceTime: false,
                            };
                        } else if(_this.insertExamineData.serviceState == '2') {
                            _this.dialogExamineTitle = "详情";
                            _this.insertExamineData.lastServiceDept = _this.insertExamineData.lastServiceDeptName;
                            _this.insertExamineDataDisabled={
                                applicant: false,
                                applicantName: false,
                                applicantTime: false,
                                approveRemark: false,
                                approveResult: false,
                                approveTime: false,
                                approver: false,
                                approverName: false,
                                dealer: false,
                                dealerName: false,
                                department: false,
                                departmentName: false,
                                hospital: false,
                                hospitalName: false,
                                id: false,
                                isAcceptOthersService: false,
                                lastServiceDept: false,
                                lastServiceDeptName: false,
                                needServiceDesc: false,
                                serviceEvaluation: false,
                                serviceNeedTime: false,
                                serviceState: false,
                                serviceStateName: false,
                                serviceType: false,
                                serviceTypeName: false,
                                servicer: false,
                                servicerPhone: false,
                                sureServiceTime: false,
                            };
                        }













                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },
            submitExamineList() {
                let _this = this;
                _this.insertExamineData.serviceNeedTime=_this.timestampToTime(_this.insertExamineData.serviceNeedTime);
                _this.insertExamineData.sureServiceTime=_this.timestampToTime(_this.insertExamineData.sureServiceTime);
                console.log( _this.insertExamineData )
                this.$http({
                    url: "/api/adscm/serviceProvider/jyService/update?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" },
                    data: _this.insertExamineData
                }).then(function(res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.isExamineDialog = false;
                        _this.getMapCharts();
                    }
                }).catch(function(catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },

            //获取经销商详细信息
            getDistributorData(id){
                let _this = this;
                this.$http({
                    url: "/api/adscm/dealer/dealer/selectById/"+id+"?tokenId=" + _this.tokenId,
                    method: "post",
                    headers: { "X-Requested-With": "XMLHttpRequest" }
                }).then(function(res) {
                    console.log( res.data )
                    if (res.data.statusCode == 200) {
                        _this.dialogDistributorList = res.data.content;
                        _this.isDistributorDialog = true;
                    } else {
                        _this.$message.error(res.data.desc);
                    }
                }).catch(function(catchres) {
                    _this.$message.error("加载失败！请重新加载...");
                });
            },

            handleClick(tab, event) {
                if (tab.name == '2') {
                    this.getMapCharts();
                }
            },
            handleSizeChange: function (size) {
                this.pagesize = size;
            },
            handleCurrentChange: function (currentPage) {
                this.currentPage = currentPage;
            },
            timestampToTime(timestamp) {
                if (timestamp) {
                    let date = new Date(timestamp);
                    let Y = date.getFullYear() + "-";
                    let M =
                        (date.getMonth() + 1 < 10
                            ? "0" + (date.getMonth() + 1)
                            : date.getMonth() + 1) + "-";
                    let D =
                        (date.getDate() < 10 ? "0" + date.getDate() : date.getDate()) + " ";
                    let h =
                        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) +
                        ":";
                    let m =
                        (date.getMinutes() < 10
                            ? "0" + date.getMinutes()
                            : date.getMinutes()) + ":";
                    return timestamp ? Y + M + D + h + m + "00" : "";
                } else {
                    return "";
                }
            }
        }
    };
</script>

<style  scoped>


</style>
